<template>
     <el-dialog :title="'正文: '+propsData.info_content" :before-close="cancelModal" :visible.sync="visible" :show-close="false" width="80%" style="margin-bottom:50px" :modal="true" :close-on-click-modal="true" :close-on-press-escape="false">
       <!-- 这里的:show-close="false"是设置不显示关闭按钮，因为弹窗显示状态值（:visible.sync）是从父组件传递的参数，如果使用自带的关闭按钮，会报出一个错误 -->
       <button type="button" aria-label="Close" class="el-dialog__headerbtn" @click.stop="cancelModal"><i class="el-dialog__close el-icon el-icon-close"></i></button>
       <!-- //  详细 -->
        <el-table :data="listData"  style="width: 100%"  highlight-current-row  default-expand-all  max-width="250" v-loading="listLoading" element-loading-text="给我一点时间">
            <el-table-column width="1000px" >
                <template slot-scope="props"> 
                    <el-form label-position="left" inline class="demo-table-expand">
                    <el-form-item label="回复: ">
                        <span>{{props.row.content}}</span>
                    </el-form-item>
                    <el-form-item>
                        <span class="foots">评论时间: <span>{{props.row.create_time}}</span></span>
                    </el-form-item>
                    </el-form>
                </template>
            </el-table-column>
        </el-table>
        <div class="pagination-container">
          <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total">
          </el-pagination>
        </div>
        <!--可自定义按钮的样式、show/hide临界点、返回的位置  -->
        <!--如需文字提示，可在外部添加element的<el-tooltip></el-tooltip>元素  -->
        <el-tooltip placement="top" content="回到顶部">
          <back-to-top transitionName="fade" :customStyle="myBackToTopStyle" :visibilityHeight="300" :backPosition="50"></back-to-top>
        </el-tooltip>
      </el-dialog>
</template>

<script>
import * as api from '@/api/main-api' // API
import BackToTop from '@/components/BackToTop' // 回到顶部
import { mapGetters } from 'vuex'

export default {
  name: 'lookReply',
  components: { BackToTop },

  computed: {
    ...mapGetters([
      'outlet_id'
    ])
  },

  props: {
    visible: {
      type: Boolean,
      default: false
    },
    propsData: Object
  },

  data() {
    return {
      // 回到顶部样式
      myBackToTopStyle: {
        right: '50px',
        bottom: '50px',
        width: '40px',
        height: '40px',
        'border-radius': '4px',
        'line-height': '45px', // 请保持与高度一致以垂直居中 Please keep consistent with height to center vertically
        background: '#e7eaf1'// 按钮的背景颜色 The background color of the button
      },

      listQuery: {
        page: 1,
        pagesize: 10
      },
      total: 0,
      listLoading: false,
      listData: []
    }
  },

  // 初始化数据
  mounted() {
    this.$nextTick(() => {
      if (this.listQuery.info_id) {
        this.fetchData()
      }
    })
  },

  methods: {
    // 控制每页调数
    handleSizeChange(val) {
      this.listQuery.pagesize = val
      this.fetchData()
    },

    // 跳页
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.fetchData()
    },

    // 关闭弹窗，触发父组件修改visible值
    cancelModal() {
      this.$emit('update:visible', false)
    },

    // 回复数据
    fetchData() {
      this.listLoading = true
      this.listQuery.info_id = this.propsData.info_id
      api.infoReplyApi(this.listQuery).then(response => {
        if (response.data.code === 0) {
          this.listData = response.data.data
          this.total = parseInt(response.data.total)
        }
        this.listLoading = false
      })
    }
  },

  watch: {
    visible(v) {
      if (v) {
        this.fetchData()
      }
    }
  }

}
</script>

